{include file="public/header"}
<body>
<div id="app" v-cloak>
    <div class="ht-main">
        <div class="ht-search">
            <el-form :inline="true" size="small">
                <el-form-item label="标题">
                    <el-input v-model="searchKey.title" placeholder="标题"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
                    <el-button type="" icon="el-icon-refresh" @click="reset">重置</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="ht-tool">
            <div class="ht-tool-left">
                <el-button type="success" size="mini" icon="el-icon-plus" @click="doAdd">添加</el-button>
                <el-button type="primary" :disabled="tableSelect.length !== 1" size="mini" icon="el-icon-edit"
                           @click="edit(tableSelect[0])">编辑
                </el-button>
                <el-button type="danger" :disabled="!tableSelect.length" size="mini" icon="el-icon-delete"
                           @click="batchDel('/admin/archives/del')">删除
                </el-button>
            </div>
            <div class="ht-tool-right"></div>
        </div>
        <div class="ht-main-body">
            <el-table :data="tableData" border header-row-class-name="ht-table-header"
                      ref="dataTable" @selection-change="handleSelectChange" row-key="id"
            >
                <el-table-column align="center" type="selection" width="39"></el-table-column>
                <el-table-column prop="id" align="center" width="50" label="ID"></el-table-column>
                <el-table-column prop="title" label="标题">
                    <template slot-scope="scope">
                        <el-link type="primary" @click="showDetail(scope.row)" style="cursor: pointer">{{scope.row.title}}</el-link>
                    </template>
                </el-table-column>
                <el-table-column align="center" prop="create_time" label="添加时间" width="180"></el-table-column>
                <el-table-column
                        align="center"
                        label="操作"
                        width="180">
                    <template slot-scope="scope">
                        <el-button @click="edit(scope.row)" size="mini" type="primary" icon="el-icon-edit"></el-button>
                        <el-button @click="del(scope.row)" size="mini" type="danger" icon="el-icon-delete"></el-button>
<!--                        <el-button @click="share(scope.row)" size="mini" type="danger">分享</el-button>-->
                    </template>
                </el-table-column>
            </el-table>
            <div class="ht-main-page">
                <el-pagination
                        @size-change="handleSizeChange"
                        @current-change="handleCurrentChange"
                        :current-page="page"
                        :page-sizes="[1,10, 200, 300, 400]"
                        :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper"
                        :total="total">
                </el-pagination>
            </div>
        </div>
    </div>
    <ht-archives-detail :show.sync="showDialog" :item-data="editData"></ht-archives-detail>
</div>
{include file="public/common"}
<script src="/static/elementUi/component/archives_detail.js"></script>
<script>
    let vs ;
    let del_url = "{:url('Archives/del')}";
    let add_url = "{:url('Archives/add')}";
    let index_url = "{:url('Archives/index')}";
    var vm = new Vue({
        el: "#app",
        data: function () {
            return {
                showDialog: false,
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                userList: [],
                sourceList: [],
                archivesList: [],
                phpList:[],
                fileManage:false,
            }
        },
        created: function () {
            vs = this;
            this.getData()
        },
        methods: {
            showDetail(row) {
                vs.showDialog = true;
                vs.editData = row;
            },
            share(row) {
                $.post("{:url('ArchivesUser/share')}",{id:row.id},function (res) {
                    if (res.code == 1) {
                        let url = res.data.url
                        layer.open({
                            type:1,
                            title:false,
                            area:['325px','325px'],
                            content:"<img src='" + url +  "'>"
                        })
                    }
                })
            },
            getArchives() {
                $.post("{:url('Archives/all')}",{search_key:vs.search_key},function (res) {
                    if (res.code == 1) {
                        vs.archivesList = res.data
                    }
                })
            },
            imageManageClose(path) {
                this.showDialog = false;
            },
            imageSubmit(path) {
                console.log("path", path)
                this.editDataTemp.litpic = path[0]
                this.editData.litpic = path[0]
                this.showDialog = false;
            },
            imageManage() {
                this.showDialog = true;
            },
            uploadSuccess(litpic, value) {
                this.editDataTemp.litpic = litpic
                this.editData.litpic = litpic
            },

            changeStatus: function (e, id) {
                axios.post("{:url('Archives/ArchivesStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            changeMenuStatus: function (e, id) {
                axios.post("{:url('Auth/menuStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            onSubmit() {
                var that = this
                $.post(add_url, that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(function () {
                            that.is_edit = false;
                            that.editData = {};
                            that.getData()
                            that.getCategory()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },

            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like'
                };
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                Helper.open("{:url('Archives/add')}")
                return false;
                this.is_edit = true
                this.content = '添加'
                this.editData = {}
            },
            edit: function (data) {
                Helper.open("{:url('Archives/edit')}?id=" + data.id)
                return false;
                this.is_edit = true
                this.content = '编辑'
                this.editData = data

                console.log(data)
            },
            goBack: function () {
                this.is_edit = false
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                                that.getCategory()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {
            page(v) {
                this.getData()
            },
            limit() {
                this.getData()
            }
        }
    })
</script>
</body>
</html>
